package nickthissen.iracing.common;

import java.util.HashMap;

import nickthissen.iracing.datamodels.Forum;

public class ForumListManager
{
	private ForumListManager() 
	{
		
	}
	
	private static ForumListManager instance;
	public static ForumListManager getInstance()
	{
		if (instance == null) instance = new ForumListManager();
		return instance;
	}
	
	public HashMap<Integer, Forum> forums;
	
	public int getForumIdFromUrl(String url)
	{
		if (url == null) return -1;
		int dotPos = url.lastIndexOf(".");
		if (dotPos == -1) return -1;
		
		int slashPos = url.lastIndexOf("/");

		String idString = url.substring(slashPos + 1, dotPos);
		return Integer.parseInt(idString);
	}
	
	public Forum getForumFromUrl(String url)
	{
		int id = this.getForumIdFromUrl(url);
		if (forums.containsKey(id)) return forums.get(id);
		return null;
	}
}
